package com.zyf.chapter02.creation.prototype;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author yifeng
 */
public class ShoppingCart {
    List<ShoppingCartItem> items = new ArrayList<>();

    public List<ShoppingCartItem> getItems() {
//        return Collections.unmodifiableList(this.getItems());
        List<ShoppingCartItem> newItems = new ArrayList<>(items.size());
        // 深拷贝
        for (ShoppingCartItem item : items) {
            ShoppingCartItem newItem = new ShoppingCartItem();
            newItem.setPrice(item.getPrice());
        }
        return newItems;
    }

    public static void main(String[] args) {
        ShoppingCart cart = new ShoppingCart();

    }
}
